unit PesquisaVendedor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFormPesquisa, DB, DBTables, StdCtrls, Grids, DBGrids, Buttons,
  ExtCtrls, DBCtrls;

type
  TFPesquisaVendedor = class(TFormPesquisa)
    Label1: TLabel;
    ENome: TEdit;
    Label2: TLabel;
    EIdentificacao: TEdit;
    Label4: TLabel;
    EGrupo: TEdit;
    procedure BtnSelecionarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BtnConsultarClick(Sender: TObject);
    procedure BtnImprimirClick(Sender: TObject);
    procedure BtnLimparClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FPesquisaVendedor: TFPesquisaVendedor;

implementation

uses CadastroVendedor, RelatorioVendedor, UFormRelatorio;

{$R *.dfm}

procedure TFPesquisaVendedor.BtnSelecionarClick(Sender: TObject);
begin
 inherited;
 FCadastroVendedor.QVendedor.Close;
 FCadastroVendedor.QVendedor.Open;
 FCadastroVendedor.QVendedor.Locate('Vend_Codigo',QPesquisa.fieldByname('Vend_Codigo').AsString,[loCaseInsensitive]);
 Self.Close;
end;

procedure TFPesquisaVendedor.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 FCadastroVendedor.Enabled:=true;
 FCadastroVendedor.Show;
 FPesquisaVendedor:=nil;
 inherited;
end;

procedure TFPesquisaVendedor.BtnConsultarClick(Sender: TObject);
begin
 QPesquisa.close;
 QPesquisa.SQL.Clear;
 QPesquisa.SQL.Add('Select * from Vendedor ');
 QPesquisa.SQL.Add('Where (Vend_Codigo = Vend_Codigo)');
 if ENome.Text <> '' then
  begin
   QPesquisa.SQL.Add(' And (Vend_Nome Like :Nom)');
   QPesquisa.ParamByName('Nom').AsString:='%' + ENome.Text +'%' ;
  end;

 if EIdentificacao.Text <> '' then
  begin
   QPesquisa.SQL.Add(' And (Vend_Ident Like :Ident)');
   QPesquisa.ParamByName('Ident').AsString:='%' + EIdentificacao.Text +'%' ;
  end;

 if EGrupo.Text <> '' then
  begin
   QPesquisa.SQL.Add(' And (Vend_grupo = :Grupo)');
   QPesquisa.ParamByName('Grupo').AsString:=EGrupo.Text;
  end;
 QPesquisa.Open;
 inherited;
end;

procedure TFPesquisaVendedor.BtnImprimirClick(Sender: TObject);
begin
  inherited;
 DSPesquisa.Enabled:=false;
 Application.CreateForm(TFRelatorioVendedor, FRelatorioVendedor);
 with FRelatorioVendedor do
  begin
   QRLNomeRelatorio.Caption:='VENDEDOR';
   QuickRep1.DataSet:=QPesquisa;
   QuickRep1.Prepare;
   QuickRep1.Preview;
   close;
  end;
 DSPesquisa.Enabled:=true;
end;

procedure TFPesquisaVendedor.BtnLimparClick(Sender: TObject);
begin
  inherited;
 ENome.Text:='';
 EIdentificacao.Text:='';
 EGrupo.Text:='';

end;

end.
